//
//  JQMainController.swift
//  sinaWeibo
//
//  Created by maoge on 16/4/16.
//  Copyright © 2016年 maoge. All rights reserved.
//

import UIKit

class JQMainController: UITabBarController {


    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = JQTabBar()
        
        tabBar.composeButtonClosure = {
            print("点击按钮")
        }
        
        //系统只读属性无法直接赋值, 可以利用KVC来赋值
        self.setValue(tabBar, forKey: "tabBar")
        
       
        
//        let tabBar = UITabBar.appearance()
//        tabBar.tintColor = UIColor.orangeColor()
        
        addChildViewControllers(JQHomeViewController(), title: "首页", imgNamed: "tabbar_home")
        
        addChildViewControllers(JQMessageController(), title: "消息", imgNamed: "tabbar_message_center")
        
        addChildViewControllers(JQDiscoverController(), title: "发现", imgNamed: "tabbar_discover")
        
        addChildViewControllers(JQProfileController(), title: "我", imgNamed: "tabbar_profile")
    }
    
    func addChildViewControllers(vc: UIViewController, title: String, imgNamed: String) {
        
        
        //默认直接设置到导航条的title , 可以通过 vc.tabBarItem.title 来设置
        vc.title = title
        
        vc.tabBarItem.image = UIImage(named: imgNamed)
        
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgNamed)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
        
//        vc.tabBarItem.setTitleTextAttributes([NSFontAttributeName : UIFont.systemFontOfSize(14)], forState: .Normal)
//        vc.tabBarItem.imageInsets = UIEdgeInsets(top: 5, left: 0, bottom: -5, right: 0)
        
        addChildViewController(UINavigationController(rootViewController: vc))
    }
}


